package com.obrempon.credit.market.ui.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.obrempon.credit.market.common.CommonDialog
import com.obrempon.credit.market.databinding.ObremponPermissionReasonDialogBinding
import com.obrempon.credit.market.event.ObremponEventPointType
import org.json.JSONObject

/**
 * ObremponCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：权限说明 dialog
 */
class ObremponPermissionReasonDialog: CommonDialog {

    private lateinit var binding: ObremponPermissionReasonDialogBinding
    private var mCallback: IDialogCallback? = null
    //事件备注
    private var eventRemark = ""

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context, remark: String) : super(context) {
        eventRemark = remark
    }
    constructor(context: Context, remark: String, callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun takeObremponRootView(): View {
        binding = ObremponPermissionReasonDialogBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initObremponView() {
    }

    override fun initObremponListener() {
        setOnClickListener(binding.buttonDeny) //取消
        setOnClickListener(binding.buttonAgree) //ok
    }

    override fun takeObremponData() {
    }

    override fun onObremponViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置埋点备注
     */
    fun addObremponKindTipsEventRemark(remark: String){
        eventRemark = remark
    }

    /**
     * 设置权限
     */
    fun setObremponPermissionReason(obj: JSONObject){
        binding.imgIcon.setImageResource(obj.optInt("iconReason"))
        binding.textPermissionTitle.text = obj.optString("titleReason")
        binding.textPermissionReason.text = obj.optString("reason")
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(ObremponEventPointType.DIALOG.OBREMPON_DIALOG_PERMISSION_REASON_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(ObremponEventPointType.DIALOG.OBREMPON_DIALOG_PERMISSION_REASON_DISMISS,eventRemark)
    }
}